<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow: hidden">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>行业</title>
<link rel="shortcut icon" href="${res}favicon.ico" type="image/x-icon" />
<link href="../framework/css/font.css" rel="stylesheet" />
<link href="../framework/miniui/themes/material/miniui.css" rel= "stylesheet" />
<link href="../framework/css/app.min.1.css" rel="stylesheet" type="text/css" />
<link href="../framework/css/app.min.2.css" rel="stylesheet" type="text/css" />
<script src="../framework/main.js" type="text/javascript"></script>
<style>
	html, html body {padding:0;border:0;margin:0;width:100%;height:100%;overflow:hidden;}
</style>
<script>
	Page.onLoad(function(){
		
	});
	
	function addTrade(){
		var row = mini.get('tradeDga').getSelected();
		var parentId = "";
		var parentName = "";
		if(row){
			parentId = row.ID;
			parentName = row.Name;
		}
		var diag = mini.open({
			width: 600,
			height : 400,
			title : "添加行业",
			url : "${ctx}mhr/tradeDialog.jhtml",
			onLoad : function(){
				$DW.mini.get('Name').focus();
				$DW.mini.get('ParentId').setText(parentName);
				$DW.mini.get('ParentId').setValue(parentId);
			},
			onOk : addSave
		});
	}
	
	function addSave(){
		var form = $DW.mini.getForm('form2');
		form.validate();
		if(form.isValid() == false){
			return;
		}
		Server.sendRequest("trade.add",form.getData(),function(response){
			if(response.Status == 1){
				top.mini.showTips({content:response.Message,state:'success'});
				$D.close();
				mini.get('tradeDga').clearSelect();
				mini.get('tradeDga').reload();
			}else{
				top.mini.warn(response.Message);
			}
		});
	}
	
	function edit(){
		var row = mini.get('tradeDga').getSelected();
		if(!row){
			top.mini.alert("@{Framework.DataGrid.PleaseSelectFirst}");
			return;
		}
		
		var options = {
			width :600,
			height : 400,
			title : "修改组织机构",
			url : "${ctx}mhr/tradeDialog.jhtml?ID=" + row.ID,
			onLoad : function(){
				try{
					$DW.$('#Name').focus();
				}catch(e){}
				$DW.mini.get('ParentInnerCode').disable();
			}	
		};
		
		options.onOk = editSave;
		
		var diag = mini.open(options);
	}
	
	function editSave() {
		var form = $DW.mini.getForm('form2');
		form.validate();
		if(form.isValid() == false){
			return;
		}
		Server.sendRequest("Trade.save",form.getData(),function(response){
			if(response.Status == 1){
				top.mini.showTips({content:response.Message,state:'success'});
				$D.close();
				mini.get('tradeDga').reload();
			}else{
				top.mini.warn(response.Message);
			}
		});
	}
	
	function del(){	
		var arr = mini.get('tradeDga').getSelectedValue();
		if(!arr||arr.length==0){
			top.mini.alert("@{Common.PleaseSelectToDeleteRowFirst}");
			return;
		}
		top.mini.confirm("注意：这是级联删除，下级行业会一起删除，您确认要删除？",function(action){
			if(action == "ok"){
				Server.sendRequest("Trade.del", {IDs:arr.join()},function(response){
					if(response.Status == 1){
						top.mini.showTips({content:response.Message,state:'success'});
						mini.get('tradeDga').reload();
					}else{
						top.mini.warn(response.Message);
					}
				});
			}
		});
	}
	
	function onRowSelected() {
		
	}
</script>
</head>
<body> 
	<div class="mini-toolbar">
	   	<a class="mini-button" plain="true"  iconCls="icon-add" onClick="addTrade()" >添加</a>
		<a class="mini-button" plain="true"  iconCls="icon-edit" id="ButtonEdit" onClick="edit()" >编辑</a>
		<a class="mini-button" plain="true"  iconCls="icon-remove"onClick="del()" >删除</a>
	</div>
	<div class="mini-fit" style="padding:10px;">
		<div id="tradeDga" treeColumn="Name" showTreeLines="true" idField="ID" parentField="ParentId" class="mini-treegrid z-depth-1" resultAsTree="false" 
				expandOnLoad="0" style="width:100%;height:100%;" showPager="false" method="Trade.tree" onnodeselect="onRowSelected">
		    <div property="columns">
		        <div type="indexcolumn"></div>
		        <div name="Name" field="Name" width="100">行业名称</div>
		        <div name="TradeCode" field="TradeCode" width="100">行业编号</div>
		        <div name="OrderFlag" field="OrderFlag" width="100">排序</div>
		    </div>
		</div>
	</div>
</body>
</html>
